<template>
  <div class="_wz_cent_main _wz_contracts">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form ref="formSearch" :model="formDataSearch" label-position="right" :label-width="120" inline>
        <FormItem label="运输企业">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="请选择运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem label="从业身份">
          <i-select v-model="formDataSearch.driverTypeCode" filterable placeholder="请选择从业身份" :label-in-value="true" clearable>
            <Option v-for="item in personType" :value="item.code" :key="item.code">{{ item.value }}</Option>
          </i-select>
        </FormItem>
        <FormItem label="印章状态" v-if="searchType">
          <i-select v-model.number="formDataSearch.newsState" filterable placeholder="请选择印章状态" clearable>
            <Option :value="0">禁用</Option>
            <Option :value="1">开启</Option>
          </i-select>
        </FormItem>
        <FormItem label="运输类型" v-if="searchType">
          <i-select v-model="formDataSearch.deptTransportCode" filterable placeholder="请选择运输类型" clearable>
            <Option v-for="item in transportationData" :value="item.code" :key="item.code">{{ item.value }}</Option>
          </i-select>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true">
      <p slot="title">列表</p>
      <p slot="extra">
        <Button type="primary" @click="addTableData">添加</Button>
      </p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>
    <Drawer :title="formTitle" v-model="formOperation" width="1000" :mask-closable="false" :draggable="true" :styles="formOperationStyles">
      <contractsAdd v-if="formOperation" @closeFun="closeFun" :selectData="selectData"></contractsAdd>
    </Drawer>
    <Drawer title="详情" v-model="formDetails" width="748" :draggable="true">
      <contractsSee v-if="formDetails" :formDetailsData="selectData"></contractsSee>
    </Drawer>

    <Modal title="上传印章" v-model="uploadSealType" width="900" :mask-closable="false" :footer-hide="true">
      <uploadSeal v-if="uploadSealType" :selectData="selectData" @closeFun="closeFun"></uploadSeal>
    </Modal>

    <Spin size="large" fix v-if="spinShow"></Spin>

  </div>
</template>
<script>

import contractsAdd from "./contractsAdd";
import uploadSeal from "./uploadSeal";
import contractsSee from "./contractsSee";
import wzTbale from "../../components/table/table";

export default {
  components: {
    contractsAdd,//添加
    contractsSee,//详情
    wzTbale,//列表
    uploadSeal,//上传印章
  },
  data() {
    return {
      uploadSealType:false,//上传印章
      searchType: false,//搜索条件
      spinShow:false,//本页加载
      formDetails: false,
      subDeptList: [],//运输企业
      personType:[],//人员类型
      transportationData:[],//运输类型
      formDataSearch: {},//搜索表单数据
      formTitle: '',
      selectData: {},
      formOperation: false,//表单左侧移出
      formOperationStyles: {//表单左侧移出css
        height: 'calc(100% - 55px)',
        overflow: 'auto',
        paddingBottom: '53px',
        position: 'static'
      },
      tableData: {
        url: this.apiUrl.coreDeptContractCoreDeptContractPageList,//请求地址
        method: 'post',//请求方式
        where: {},//搜索条件
        height: 'auto',//表格高度 auto
        page: true,//分页是否使用
        columns: [//表头数据
          {type: 'index', width: 70, align: 'center', title: '序号'},
          {title: '运输企业', minWidth: 260, key: 'deptName'},
          {title: '运输类型', minWidth: 140, key: 'deptTransportName'},
          {title: '从业人员', minWidth: 140, key: 'driverTypeName'},
          {title: '合同期限', minWidth: 100, key: 'employContentLimit'},
          {
            title: '聘用合同', minWidth: 180, key: 'employContent', render: (h, params) => {
              return h('Tag', {props: {type: 'dot', color: params.row.employContent ? 'success' : 'warning'}}, params.row.employContent ? '存在' : '不存在');
            }
          },
          {
            title: '承诺书', minWidth: 180, key: 'promiseContent', render: (h, params) => {
              return h('Tag', {props: {type: 'dot', color: params.row.promiseContent ? 'success' : 'warning'}}, params.row.promiseContent ? '存在' : '不存在');
            }
          },
          {
            title: '责任状', minWidth: 180, key: 'dutyContent', render: (h, params) => {
              return h('Tag', {props: {type: 'dot', color: params.row.dutyContent ? 'success' : 'warning'}}, params.row.dutyContent ? '存在' : '不存在');
            }
          },
          {
            title: '告知书', minWidth: 180, key: 'noticeContent', render: (h, params) => {
              return h('Tag', {props: {type: 'dot', color: params.row.noticeContent ? 'success' : 'warning'}}, params.row.noticeContent ? '存在' : '不存在');
            }
          },
          {
            title: '印章状态', width: 100, key: 'signatureState',
            render: (h, params) => {
              return h('i-switch', {
                props: {
                  size: 'large',
                  value: params.row.signatureState == 1
                },
                on: {
                  'on-change': (value) => {//触发事件是on-change,用双引号括起来，
                    params.row.signatureState = value ? 1 : 0;
                    let data = params.row;
                    let formData = new FormData();
                    for (var key in data) {
                      formData.append(key, data[key]);
                    }
                    this.axios.post(this.apiUrl.coreDeptContractCoreDeptContractSaveOrUpdate, formData).then(res => {
                      if (!!res) {
                        this.$Message.success('操作成功');
                        this.$refs.wzTbale.tableLoadData(true);
                      }
                    }).catch(err => {
                      console.log("失败", err)
                    })
                  }
                },
                scopedSlots: {
                  open: () => h('span', '开启'),
                  close: () => h('span', '禁用')
                }
              })
            }
          },
          {
            title: '操作', fixed: 'right', width: 120,
            render: (h, params) => {
              let operationButtons = [];
              operationButtons.push(h('span', {
                style: {"color": "#2d8cf0", "cursor": "pointer"},
                on: {
                  click: () => {
                    this.selectData = params.row;
                    this.formDetails = true;
                  }
                }
              }, '查看'))
              var buttonList = [];

              //上传
              buttonList.push(h('DropdownItem', {
                nativeOn: {
                  click: () => {
                    this.selectData = JSON.parse(JSON.stringify(params.row));
                    this.uploadSealType = true;
                  }
                }
              }, '上传'))

              //修改
              buttonList.push(h('DropdownItem', {
                nativeOn: {
                  click: () => {
                    this.formTitle = '修改';
                    this.selectData = JSON.parse(JSON.stringify(params.row));
                    this.formOperation = true;
                  }
                }
              }, '修改'))
              //删除
              buttonList.push(h('DropdownItem', {
                nativeOn: {
                  click: () => {
                    var that = this;
                    that.$Modal.confirm({
                      title: '删除提醒',
                      content: '确定要删除选中的记录？',
                      onOk: () => {
                        that.spinShow = true;
                        that.axios.post(that.apiUrl.coreDeptContractCoreDeptContractDelete ,{uuid:params.row.uuid}).then(res => {
                          that.spinShow = false;
                          if (!!res) {
                            that.$Message.success('删除成功');
                            that.$refs.wzTbale.tableLoadData();
                          }
                        }).catch(err => {
                          console.log("失败", err)
                        })
                      },
                      onCancel: () => {
                        //点击取消
                      }
                    });
                  }
                }
              }, '删除'))

              if (buttonList.length > 0) {
                if(operationButtons.length > 0){
                  operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
                }
                operationButtons.push(h('Dropdown', {props: {trigger: "hover", transfer: true}},
                  [
                    h('span', {style: {"color": "#2d8cf0", "cursor": "pointer"}}, '更多▼'),
                    h('DropdownMenu', {slot: "list"}, buttonList)
                  ])
                )
              }
              return operationButtons;
            }
          },
        ],
        format: {//返回数据格式
          list: ['data'],//数据list
          count: ['count'],//数据总量
        },
      },
    }
  },
  beforeCreate() {//beforeCreate创建前状态

  },
  created() {//created创建完毕状态
  },
  beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

  },
  mounted() {//mounted 挂载结束状态
    var that = this;
    //运输企业
    that.axios.post(that.apiUrl.coreDeptCoreDeptList,{}).then(res => {
      if (!!res) {
        that.subDeptList = res.data.data;
      }
    }).catch(err => {
      console.log("失败", err)
    })


    //企业类型
    that.axios.post(that.apiUrl.systemDictSystemDictList,{type:'transport_type'}).then(res => {
      if (!!res) {
        that.transportationData = res.data.data;
      }
    }).catch(err => {
      console.log('失败', err);
    })


    //从业类型
    that.axios.post(that.apiUrl.systemDictSystemDictList, {type: 'person_type'}).then(res => {
      if (!!res) {
        that.personType = res.data.data;
      }
    }).catch(err => {
      console.log('失败', err);
    })
  },
  methods: {//执行的方法
    addTableData() {//table添加
      this.formTitle = '添加';
      this.selectData = {};
      this.formOperation = true;
    },
    searchSubmit() {//搜索
      this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
      this.$refs.wzTbale.tableLoadData(true);
    },
    //添加修改触发后关闭刷新
    closeFun(data) {
      var that = this;
      if (data) {//添加修改 刷新表单
        that.$refs.wzTbale.tableLoadData();
      }
      that.formOperation = false;
      that.uploadSealType = false;

    },
  },
  watch: {//监听

  },
  beforeUpdate() {//beforeUpdate 更新前状态

  },
  updated() {//updated 更新完成状态

  },
  beforeDestroy() {//beforeDestroy 销毁前状态

  },
  destroyed() {//destroyed 销毁完成状态

  }
}
</script>
<style lang="less">
._wz_contracts {
  display: flex;
  flex-direction: column;
}
</style>
